package Test;

import java.util.InputMismatchException;
import java.util.Scanner;

import com.demo.ATM;
import com.exception.InputNotCorrect;
import com.exception.InsufficientFundException;
import com.exception.NotNegativeNumber;

public class BankTest {
	
	public static void main(String[] args) {
		ATM atm=new ATM("12345-34567");
		atm.show();
		boolean flag=true;
		boolean inputFlag=false;
		
		while(flag){
			int num = 0;
			try{
				num=new Scanner(System.in).nextInt();
				System.out.println(num);
				for(int i=1;i<=4;i++){
					if(num==i){
						inputFlag=true;
						break;
					}
				}
				if(!inputFlag){
					throw new InputNotCorrect();
				}

			}catch(InputMismatchException e){
				System.out.println("您输入的不是数字,请重新输入");
				continue;
			} catch (InputNotCorrect e) {
				System.out.println("您的输入不正确,请重新输入");
				continue;
			}
			switch(num){
				case 1:
					System.out.println("请输入存款金额");
					while(true){
						try {
							double banlance=new Scanner(System.in).nextDouble();
							atm.deposit(banlance);
							atm.show();
							break;
						} catch (NotNegativeNumber e) {
							System.out.println("请输入正确的金额，不能为负数");
						} catch(InputMismatchException e){
							System.out.println("请输入正确的金额，不能为字符");
						}
					}
					break;
				case 2:
					System.out.println("输入取款金额");
					while(true){
						try {
							double money=new Scanner(System.in).nextDouble();
							atm.withDraw(money);
							atm.show();
							break;
						} catch(InputMismatchException e){
							System.out.println("请输入正确的金额，不能为字符");
						} catch (InsufficientFundException e) {
							System.out.println("抱歉，余额不足");
						} catch (NotNegativeNumber e) {
							System.out.println("请输入正确的金额，不能为负数");
						}
					}
					break;
				case 3:
					atm.showBalance();
					atm.show();
					break;
				case 4:
					flag = false;
					System.out.println("交易完成，请取回您的卡");
					break;
			}
			inputFlag=false;
		}
	}
	
}
